import time
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.common.by import By

#编写自动化脚本步骤
#1. 打开浏览器----驱动管理（国内谷歌浏览器用edge驱动），并配置edge环境选项
driver_path = EdgeChromiumDriverManager().install()
edge_options = Options()
edge_options.add_argument("--remote-allow-origins=*")
#2. 创建浏览器驱动对象
driver = webdriver.Edge(service=Service(driver_path), options=edge_options)
#2.输入百度网址url
driver.get("https://www.baidu.com")
#3.找到百度输入框，输入关键词“迪丽热巴”
driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("迪丽热巴")
time.sleep(3)
#4.点击“百度一下”按钮
driver.find_element(By.CSS_SELECTOR,"#su").click()
time.sleep(3)
#5.关闭浏览器
driver.quit()
